package sg.edu.nus.iss.jass.persistence;

import java.util.List;

import sg.edu.nus.iss.jass.datastore.BaseDAO;
import sg.edu.nus.iss.jass.datastore.exception.DataStoreException;
import sg.edu.nus.iss.jass.datastore.impl.Selector;
import sg.edu.nus.iss.jass.dto.Action;
import sg.edu.nus.iss.jass.util.Util;

public class ActionDAO extends BaseDAO {
	
	public Action getActionByStatus(String status) throws DataStoreException {
		List<Action> actionList = null;
		Action result = null;
		try {
			actionList = select(Action.class, (new Selector()).eq("status", status.toUpperCase()));
		} catch(DataStoreException e) {
			//e.printStackTrace();
			//throw new ControllerException(ErrorCodeConstants.ERROR_DATASTORE, MessageKeyManager.getMessage("error.dataStore"));
		}
		if (!Util.isEmpty(actionList)) {
			result = actionList.get(0);
		}
		return result;
	}
	
	/*
	public void initAddOfAction() throws DataStoreException {
		List<Action> actionList = new ArrayList<Action>();
		Action a1 = new Action();
		a1.setStatus("APPLIED");
		actionList.add(a1);
		a1 = new Action();
		a1.setStatus("CONTACTED");
		actionList.add(a1);
		a1 = new Action();
		a1.setStatus("REJECTED");
		actionList.add(a1);
		a1 = new Action();
		a1.setStatus("INTERVIEWED");
		actionList.add(a1);
		saveObjects(actionList);
	}
	
	public static void main(String [] args) throws Exception {
		ActionDAO dao = new ActionDAO();
		dao.initAddOfAction();
	}
	*/

}
